package app.netant.book.soshuw;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class SoshuwDetail extends BaseDetail {

	public SoshuwDetail(String netSite) {
		super(netSite);
		this.preHref = "https://www.soshuw.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main #main .txt_top .xiazai .txt_info .show_num h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("txt下载");
			if(idx>0){
				title = title.substring(0,idx);
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main #main .txt_top .xiazai .txt_info .show_num ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main #main .txt_top .xiazai .txt_info .intro .txt_description");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main #main .txt_top #down_txt_url .zip_down a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("全部章节")>0){
				String href = parts.get(i).attr("href");
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
				
				int idx = href.lastIndexOf(".");
				String exp = href.substring(idx);
				System.out.println("【Exp】:"+exp);
				String title = this.entity.getNovelName();
				this.entity.setNovelFullName(title+exp);
				
				break;
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".main .crumbs a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		SoshuwDetail detail = new SoshuwDetail("https://www.soshuw.com/txt/HuaXiaGaoShouYiShiZhongSheng.html");
		detail.test();
	}



}
